clear
use county_outcomes_dta

gen cty_fips=state*1000+county
rename state statechetty
rename county countychetty
merge 1:m cty_fips using "justnormasylum.dta"
rename _merge mergectyoutcomesOppAtlas
save OppAtlas_NormalAsylum.dta, replace

clear
use cty_covariates.dta
gen cty_fips=state*1000+county
drop state cz czname county
merge 1:m cty_fips using OppAtlas_NormalAsylum.dta
rename _merge mergectycovariates

local vars kid_pooled_pooled_blw_p50_n kid_pooled_pooled_n
foreach x of local vars{
gen ln`x' = ln(`x')
}

save OppAtlas_NormalAsylum.dta, replace

clear
use online_table4-2-1.dta
gen cty_fips=cty1990
drop county_name cz cz_name cz_pop2000 statename state_id stateabbrv
merge 1:m cty_fips using OppAtlas_NormalAsylum.dta
rename _merge mergetable421

#delimit ;
local vars cs_elf_ind_man ann_avg_job_growth_2004_2013 ln_wage_growth_hs_grad 
frac_coll_plus2000 cty_pop2000 kid_pooled_pooled_n 
ccd_exp_tot ccd_pup_tch_ratio gsmn_math_g3_2013 tuition 
two_par_pooled_pooled_p25 two_par_pooled_pooled_p75 frac_years_xw_pooled_pooled 
cs_race_theil_2000 cs00_seg_inc cs00_seg_inc_pov25 cs00_seg_inc_aff75;

#delimit ;

foreach z of local vars{;

di "`z'";

reghdfe `z' hasnormalschool if hasnormalorasylum==1, absorb(statechetty) cluster(statechetty);
outreg2 using covars.xls, append excel dec(2);
su `z' if e(sample)==1;

#delimit ;
tabout hasnormalschool if hasnormalorasylum==1 using sumstatstabout.xls,
append c(mean `z' sd `z') npos(row) f(2)  layout(row) sum show(none); 
};

#delimit cr
save causal_normalasylum.dta, replace
